

package com.hexinfo.dmpro.dev.data.transfer.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hexinfo.dmpro.dev.data.transfer.model.DesensitizeFieldList;
import com.hexinfo.dmpro.dev.data.transfer.service.IDesensitizeFieldListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;


/**
 * 脱敏字段配置表
 *
 * @author yyh.huang
 * @date 2023-09-19 19:04:23
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/api/desensitizefieldlist")
@Api(value = "desensitizefieldlist", tags = "脱敏字段配置表管理")
public class DesensitizeFieldListController {

    private final IDesensitizeFieldListService desensitizeFieldListService;

    /**
     * 分页查询
     *
     * @param page                 分页对象
     * @param desensitizeFieldList 脱敏字段配置表
     *                             WrapperEnhancer.like(desensitizeFieldList); //自动拼接存在值sql的方法
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public ResponseEntity<Object> getDesensitizeFieldListPage(Page page, DesensitizeFieldList desensitizeFieldList) {
        return ResponseEntity.ok(desensitizeFieldListService.queryList(page, desensitizeFieldList));
    }

    /**
     * @Method reset
     * @Param
     * @Return org.springframework.http.ResponseEntity<java.lang.Object>
     * @Description 脱敏字段配置刷新
     * @Author Wang zhihao
     * @Date 2024/1/5 15:22
     * @Version V1.0
     */
    @ApiOperation(value = "脱敏字段配置刷新", notes = "脱敏字段配置重置")
    @GetMapping("/reset")
    public ResponseEntity<Object> reset() {
        log.info("脱敏字段配置刷新");
        desensitizeFieldListService.reset();
        return ResponseEntity.ok("ok");
    }

    /**
     * @Method getDesensitizeFieldListNoPage
     * @Param
     * @Return org.springframework.http.ResponseEntity<java.lang.Object>
     * @Description 不分页获取所有数据
     * @Author Wang zhihao
     * @Date 2024/1/2 14:37
     * @Version V1.0
     */
    @ApiOperation(value = "不分页获取所有数据", notes = "不分页获取所有数据")
    @GetMapping("/noPage")
    public ResponseEntity<Object> getDesensitizeFieldListNoPage() {
        return ResponseEntity.ok(desensitizeFieldListService.queryListNoPage());
    }

    @ApiOperation(value = "新增脱敏字段配置表", notes = "新增脱敏字段配置表")
    @PostMapping
    public ResponseEntity<Object> save(@RequestBody DesensitizeFieldList desensitizeFieldList) {
        desensitizeFieldListService.create(desensitizeFieldList);
        return ResponseEntity.ok(true);
    }

    /**
     * 修改脱敏字段配置表
     *
     * @param desensitizeFieldList 脱敏字段配置表
     * @return R
     */
    @ApiOperation(value = "修改脱敏字段配置表", notes = "修改脱敏字段配置表")
    @PutMapping
    public ResponseEntity<Object> updateById(@RequestBody DesensitizeFieldList desensitizeFieldList) {
        return ResponseEntity.ok(desensitizeFieldListService.updateById(desensitizeFieldList));
    }

    /**
     * 通过id删除脱敏字段配置表
     *
     * @param ids id
     * @return R
     */
    @ApiOperation(value = "通过id删除脱敏字段配置表", notes = "通过id删除脱敏字段配置表")
    @DeleteMapping("/{ids}")
    public ResponseEntity<Object> removeByIds(@PathVariable("ids") @NotNull List<String> ids) {
        return ResponseEntity.ok(desensitizeFieldListService.removeByIds(ids));
    }

    /**
     * 通过id禁用脱敏字段配置表
     *
     * @param ids id
     * @return R
     */
    @ApiOperation(value = "通过id禁用脱敏字段配置表", notes = "通过id禁用脱敏字段配置表")
    @PutMapping("/disabled/{ids}")
    public ResponseEntity<Object> disabledByIds(@PathVariable("ids") @NotNull List<String> ids) {
        desensitizeFieldListService.disabledByIds(ids);
        return ResponseEntity.ok("ok");
    }

}
